// $Id: loghandler.h 65 2004-10-27 21:44:50Z hansemil $
#ifndef LOGHANDLER_H
#define LOGHANDLER_H

#include <list>
#include <map>
#include "singleton.h"
#include "logger.h"

/**
 * This class tells std::map how to sort a bunch of strings.
 */
class MapCompareString {
public:
	bool operator() (const char* s1, const char* s2) const {
		return strcmp(s1, s2) < 0;
	}
};

/**
 * LogHandler takes care of all loggable information that the simulator generates and forwards it to "Loggers" that creates propper logs. Every "event" (thing that happens) in the simulator should generate a call to the appropriate method in LogHandler.
 */
class LogHandler : public Singleton<LogHandler> {
public:
	~LogHandler();

	void addLogger(Logger *);
	bool addLogger(Logger *, const char *);

	/*
	 * "Event" methods
	 */
	// TODO: Insert lots and lots of logging methods here
	// TODO: And DON'T forget to add them all to the Logger baseclass (and apropriate Logger subclasses)
	// TODO: All methods MUST call the corespondent method on ALL registered Loggers!
	// TODO: Naming convension: LogHandler methods MUST be named as [Class]_[Method]...
	// TODO: First parameter MUST be sender (this)
	void main_seed(unsigned int);
	void eos_init_start(void *);
	void eos_simulate_start(void *);
	void eos_simulate_stop(void *);
	void node_node(void *);
	void node_routeFile(void *, void *, void *, unsigned char);
	void node_requestFile(void *, void *, bool);
	void node_transfer(void *, void *, unsigned char);
	void clock_tick(unsigned int);
	void network_transfer(void *, void *, unsigned int);

protected:
	LogHandler();
	friend class Singleton<LogHandler>;

private:
	unsigned int m_randomSeed;
	std::list<Logger *> m_loggers;

	// TODO: Add a sorter-function to map (http://www.sgi.com/tech/stl/Map.html) !!!!!!!!!!!!
	/// List of logger event register lists
	std::map<const char *, std::list<Logger *>*, MapCompareString> m_loggerEventLists;

	/*
	 * Lists containg what Logger that is registered to what "event"
	 * These lists MUST be added to m_loggerEventLists in the LogHandler constructor!
	 */
	std::list<Logger *> m_node_node_list;
	std::list<Logger *> m_node_routeFile_list;
	std::list<Logger *> m_node_requestFile_list;
	std::list<Logger *> m_node_transfer_list;
	std::list<Logger *> m_clock_tick_list;
	std::list<Logger *> m_network_transfer_list;

};

#endif
